#!/usr/bin/env python
# -*- coding:utf-8 -*-
# 查询IP归属地

import requests,urllib,time

slblog='/data/logs/slbip.log'

with open(slblog,'r') as f:
    ips = [ record.split()[1] for record in f.readlines()]
for ip in ips:
    query = requests.get("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip).json()
    print query['data']['ip'],query['data']['city'].encode('utf-8')
    time.sleep(0.1)